package com.example.demo.demos.web.Controller;

import com.example.demo.demos.web.Services.VulnService;
import com.example.demo.demos.web.po.Vuln;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: demo1
 * @BelongsPackage: com.example.demo.demos.web.Controller
 * @Author: Hu1er
 * @CreateTime: 2023-06-28  17:12
 * @Description: TODO
 * @Version: 1.0
 */

@Controller
public class VulnController {
    @Autowired
    private VulnService vulnService;

    /**
     * @Description 添加漏洞信息
     * @author Hu1er
     * @version 1.17.0
     * @date 2023/6/28
     */
    @PostMapping ("/vuln/add")
    @ResponseBody
    public String addVuln(Vuln vuln){
        int result = vulnService.add(vuln);
        if (result > 0){
            return "成功添加漏洞"+result+"条";
        }else {
            return "添加漏洞失败";
        }

    }
    @PostMapping ("/vuln/select")
    @ResponseBody
    public List<Vuln> select(String vulnName){
        List<Vuln> result = vulnService.selectByNameFuzz(vulnName);
        if (!result.isEmpty()){
            return result;
        }else {
            return null;
        }
    }
    @PostMapping ("/vuln/update")
    @ResponseBody
    public String update(Vuln vuln){
        int result = vulnService.update(vuln);
        if (result > 0){
            return "成功修改漏洞"+result+"条";
        }else {
            return "修改漏洞失败";
        }
    }
    @PostMapping ("/vuln/del")
    @ResponseBody
    public String del(int id){
        int result = vulnService.del(id);
        if (result > 0){
            return "成功删除漏洞"+result+"条";
        }else {
            return "删除漏洞失败";
        }
    }



}
